﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CustomizationMaintEntry
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args = null)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new ThreadExceptionEventHandler(AppThreadException);
            if (System.Diagnostics.Process.GetProcessesByName("CustomizationMaintEntry").ToList().Count > 1)
            {
                System.Environment.Exit(0);
            }
            if (args.Length >= 4)
            {
                MyData.strEpicorUserID = args[2];
                MyData.strEpicorUserPass = args[3];
            }
            if (args.Length == 5)
            {
                MyData.strEpicorCompany = args[4];
            }
            if (args.Length>0 && args[0] == "Auto")
            {
                string strDataBase = "EPICOR10";
                if (args.Length > 1)
                { strDataBase = args[1].ToUpper(); }
                Application.Run(new frmVersionSelect(true, strDataBase));
            }
            else
            {
                Application.Run(new frmVersionSelect(false, "EPICOR10"));
            }
        }

        /// <summary>
        /// 在发生未捕获线程异常时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="Error"></param>
        public static void AppThreadException(object sender, ThreadExceptionEventArgs Error)
        {
            try
            {
                System.Diagnostics.StackTrace abc = new System.Diagnostics.StackTrace();
                System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(true));
                MessageBox.Show(Error.Exception.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            { MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
    }
}
